/*============================================================================*/
/*  ファイル : test.c                                                         */
/*  機能概要 : 試験用ソースファイル                                           */
/*  更新履歴 : 2011/01/20 新規作成                                            */
/*============================================================================*/
/* Include Files */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "strlib.h"
/* Defines */
#define SEPARATOR	("------------------------------\n")
/* Types */
/* External Functions */
/* External Variables */
/* Global Variables */
/* Local Variables */
/* Local Functions */
int strtail_test( void );
int strshift_test( void );
int strreplace_test( void );
int substr_test( void );
int strreverse_test( void );
int strmatch_test( void );
int strrstr_test( void );
/*============================================================================*/
/*  名称     : main - テスト用main関数                                        */
/*  呼出し   : none                                                           */
/*  戻り値   : 0 - 正常                                                       */
/*============================================================================*/
int main( void )
{
	/* Local Variables */
	int ret = 0;

	printf(SEPARATOR);
	ret = strtail_test();
	printf("strtail test = %s\n", (ret == 0) ? "OK": "NG");

	printf(SEPARATOR);
	ret = strshift_test();
	printf("strshift test = %s\n", (ret == 0) ? "OK": "NG");

	printf(SEPARATOR);
	ret = strreplace_test();
	printf("strreplace test = %s\n", (ret == 0) ? "OK": "NG");

	printf(SEPARATOR);
	ret = substr_test();
	printf("substr test = %s\n", (ret == 0) ? "OK": "NG");

	printf(SEPARATOR);
	ret = strreverse_test();
	printf("strreverse test = %s\n", (ret == 0) ? "OK": "NG");

	printf(SEPARATOR);
	ret = strmatch_test();
	printf("strmatch test = %s\n", (ret == 0) ? "OK": "NG");

	return 0;
}

/*============================================================================*/
/*  名称     : strtail_test - strtailテスト用関数                             */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int strtail_test( void )
{
	/* Local Variables */
	char teststr[64] = "strtail_test : stringalpha";
	char *rtnptr = NULL;

	printf("strtail test #1 : Replace_test\n");
	rtnptr = strtail(teststr);
	if (rtnptr == NULL) {
		printf("Test #1 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#1_result: OK (teststr = %p, rtnptr = %p)\n", teststr, rtnptr);
	printf("\n");

	printf("strtail test #2 : NULL String buffer\n");
	rtnptr = strtail(NULL);
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#2_result: OK\n");
	printf("\n");


	return 0;
}

/*============================================================================*/
/*  名称     : strshift_test - strshiftテスト用関数                           */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int strshift_test( void )
{
	/* Local Variables */
	char teststr[64] = "strshift_test : stringalpha";
	char *rtnptr = NULL;

	printf("strshift test #1 : shift_test\n");
	rtnptr = strshift(teststr , 5);
	if (rtnptr == NULL) {
		printf("Test #1 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#1_result: OK (teststr = %s\n rtnptr = %s)\n", teststr, rtnptr);
	printf("\n");

	printf("strtail test #2 : NULL String buffer\n");
	rtnptr = strshift(NULL, 5);
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr =%s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#2_result: OK\n");
	printf("\n");

	return 0;
}

/*============================================================================*/
/*  名称     : strreplace_test - strreplaceテスト用関数                       */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int strreplace_test( void )
{
	/* Local Variables */
	char teststring_a[64] = "strreplace_test : stringalpha";
	char *rtnptr = NULL;

	printf("strreplace test #1 : Replace_test\n");
	rtnptr = strreplace(teststring_a, "string", "STRING");
	if (rtnptr == NULL) {
		printf("Test #1 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#1_result: OK (%s)\n", rtnptr);
	printf("\n");

	rtnptr = NULL;
	printf("strreplace test #2 : NULL String buffer\n");
	rtnptr = strreplace(NULL, "string", "STRING");
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#2_result: OK\n");
	printf("\n");

	rtnptr = NULL;
	printf("strreplace test #3 : NULL from buffer\n");
	rtnptr = strreplace(teststring_a, NULL, "STRING");
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#3_result: OK\n");
	printf("\n");

	rtnptr = NULL;
	printf("strreplace test #4 : NULL to buffer\n");
	rtnptr = strreplace(teststring_a, "string", NULL);
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#4_result: OK\n");
	printf("\n");

	return 0;
}

/*============================================================================*/
/*  名称     : substr_test - substrテスト用関数                               */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int substr_test( void )
{
	/* Local Variables */
	char teststr[64] = "substr_test : stringalpha";
	char subbuf[16];
	char *rtnptr = NULL;

	memset(subbuf, 0, sizeof(subbuf));
	printf("substr test #1 : sub String test\n");
	rtnptr = substr(subbuf, teststr, 5, 10);
	if (rtnptr == NULL) {
		printf("Test #1 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#1_result: OK (%s)\n", rtnptr);
	printf("\n");

	printf("substr test #2 : buffer NULL test\n");
	rtnptr = substr(NULL, teststr, 5, 10);
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#2_result: OK \n");
	printf("\n");

	printf("substr test #3 : string NULL test\n");
	rtnptr = substr(subbuf, NULL, 5, 10);
	if (rtnptr != NULL) {
		printf("Test #3 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#3_result: OK \n");
	printf("\n");

	printf("substr test #4 : s_pos < 0 \n");
	rtnptr = substr(subbuf, teststr, -1, 10);
	if (rtnptr != NULL) {
		printf("Test #4 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#4_result: OK \n");
	printf("\n");

	printf("substr test #5 : e_pos = s_pos \n");
	rtnptr = substr(subbuf, teststr, 5, 5);
	if (rtnptr != NULL) {
		printf("Test #5 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#5_result: OK \n");
	printf("\n");

	printf("substr test #6 : e_pos < s_pos \n");
	rtnptr = substr(subbuf, teststr, 10, 5);
	if (rtnptr != NULL) {
		printf("Test #6 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#6_result: OK \n");
	printf("\n");

	return 0;
}

/*============================================================================*/
/*  名称     : strreverse_test - strreverseテスト用関数                       */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int strreverse_test( void )
{
	/* Local Variables */
	char teststr[64] = "strreverse_test : stringalpha";
	char *rtnptr = NULL;

	printf("strreverse test #1 : String Reverse test\n");
	rtnptr = strreverse(teststr);
	if (rtnptr == NULL) {
		printf("Test #1 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#1_result: OK (%s)\n", rtnptr);
	printf("\n");

	printf("strreverse test #2 : String NULL test\n");
	rtnptr = strreverse(NULL);
	if (rtnptr != NULL) {
		printf("Test #2 NG rtnptr = %s, errno = %d\n", rtnptr, errno);
		return -1;
	}
	printf("#2_result: OK \n");
	printf("\n");

	return 0;
}

/*============================================================================*/
/*  名称     : strmatch_test - strmatchテスト用関数                           */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int strmatch_test( void )
{
	/* Local Variables */
	char teststr[64] = "strmatch_test : stringalpha";
	int rtn = 0;

	printf("strreverse test #1 : String Search test\n");
	rtn = strmatch(teststr, "strmatch_test : stringalpha");
	if (rtn == 0) {
		printf("Test #1 NG rtn = %d, errno = %d\n", rtn, errno);
		return -1;
	}
	printf("#1_result: OK (%d)\n", rtn);
	printf("\n");

	printf("strreverse test #2 : String mismatch test\n");
	rtn = strmatch(teststr, "strmatch_test : STRINGalpha");
	if (rtn == 1) {
		printf("Test #2 NG rtn = %d, errno = %d\n", rtn, errno);
		return -1;
	}
	printf("#2_result: OK (%d)\n", rtn);
	printf("\n");

	printf("strreverse test #3 : String wildcard(*) test\n");
	rtn = strmatch(teststr, "strmatch_test : *alpha");
	if (rtn == 0) {
		printf("Test #3 NG rtn = %d, errno = %d\n", rtn, errno);
		return -1;
	}
	printf("#3_result: OK (%d)\n", rtn);
	printf("\n");

	printf("strreverse test #4 : String wildcard(?) test\n");
	rtn = strmatch(teststr, "strmatch_test : stri?galpha");
	if (rtn == 0) {
		printf("Test #4 NG rtn = %d, errno = %d\n", rtn, errno);
		return -1;
	}
	printf("#4_result: OK (%d)\n", rtn);
	printf("\n");

	printf("strreverse test #5 : String NULL test\n");
	rtn = strmatch(NULL, "strmatch_test : stri?galpha");
	if (rtn != -1) {
		printf("Test #4 NG rtn = %d, errno = %d\n", rtn, errno);
		return -1;
	}
	printf("#5_result: OK (%d)\n", rtn);
	printf("\n");

	printf("strreverse test #6 : From NULL test\n");
	rtn = strmatch(teststr, NULL);
	if (rtn != -1) {
		printf("Test #6 NG rtn = %d, errno = %d\n", rtn, errno);
		return -1;
	}
	printf("#6_result: OK (%d)\n", rtn);
	printf("\n");

	return 0;
}

/*============================================================================*/
/*  名称     : memswap_test - memswapテスト用関数                             */
/*  呼出し   : none                                                           */
/*  戻り値   :  0 - 正常                                                      */
/*             -1 - 異常                                                      */
/*============================================================================*/
int memswap_test( void )
{




	return 0;
}
